<?php


namespace app\api\controller\v1;


use app\api\model\CityModel;
use app\api\model\FinReportModel;
use app\common\controller\UserBaseController;

class FinController extends UserBaseController
{
    function city_id_name_map()
    {
        $cities = (new CityModel())->query_all(0, 100);
        $m = [];
        foreach ($cities as $e) {
            $m[$e['id']] = $e['name'];
        }
        return $m;
    }

    function user_ride_order_listAction()
    {
        $this->paramlist = [
            'city_id' => 'optstring',
            'pno' => 'optint',
            'psize' => 'optint',
            'start_time' => 'datetime',
            'end_time' => 'datetime'
        ];
        $this->check_params();
        $this->check_token();

        list($l, $c) = (new FinReportModel())->user_order_list($this->city_id_name_map(), $this->city_id, $this->argv['start_time'], $this->argv['end_time'], $this->argv['pos'], $this->argv['limit']);
        $this->resp['list'] = $l;
        $this->resp['total'] = $c;

        return $this->ret_resp();
    }
    function user_ride_order_amount_adjusted_listAction()
    {
        $this->paramlist = [
            'city_id' => 'optstring',
            'pno' => 'optint',
            'psize' => 'optint',
            'start_time' => 'datetime',
            'end_time' => 'datetime'
        ];
        $this->check_params();
        $this->check_token();

        list($l, $c) = (new FinReportModel())->user_order_adjust_amount_list($this->city_id_name_map(), $this->city_id, $this->argv['start_time'], $this->argv['end_time'], $this->argv['pos'], $this->argv['limit']);
        $this->resp['list'] = $l;
        $this->resp['total'] = $c;

        return $this->ret_resp();
    }

    /*
        function user_ride_order_amount_adjusted_csvAction()
        {
            $this->paramlist = [
                'city_id' => 'optstring',
                'start_time' => 'datetime',
                'end_time' => 'datetime'
            ];
            $this->check_params();
            $this->check_token();

            if ($this->argv['end_time'] < $this->argv['start_time']) {
                throw_myexception(X_ERROR);
            }

            if (strtotime($this->argv['end_time']) - strtotime($this->argv['start_time']) >= 31 * 24 * 3600) {
                throw_myexception(X_ERROR, "查询时间跨度过大！");
            }

            (new FinReportModel())->user_order_adjust_amount_list_export($this->city_id_name_map()[$this->city_id],
                $this->city_id,
                $this->argv['start_time'],
                $this->argv['end_time']);
        }

        function user_ins_balance_csvAction()
        {
            $this->paramlist = [
                'city_id' => 'optstring',
                'pno' => 'optint',
                'psize' => 'optint',
            ];
            $this->check_params();
            $this->check_token();

            (new FinReportModel())->underbalance_user_export($this->city_id_name_map()[$this->city_id], $this->city_id);
        }
    */
    function user_ins_balance_listAction()
    {
        $this->paramlist = [
            'city_id' => 'optstring',
            'pno' => 'optint',
            'psize' => 'optint',
        ];
        $this->check_params();
        $this->check_token();

        list($l, $c) = (new FinReportModel())->poor_user_list($this->city_id_name_map(), $this->city_id, $this->argv['pos'], $this->argv['limit']);
        $this->resp['list'] = $l;
        $this->resp['total'] = $c;

        return $this->ret_resp();
    }

    function user_membership_order_listAction()
    {
        $this->paramlist = [
            'city_id' => 'optstring',
            'pno' => 'optint',
            'psize' => 'optint',
            'start_time' => 'datetime',
            'end_time' => 'datetime'
        ];
        $this->check_params();
        $this->check_token();

        list($l, $c) = (new FinReportModel())->user_membership_order_list($this->city_id_name_map(), $this->city_id, $this->argv['start_time'], $this->argv['end_time'], $this->argv['pos'], $this->argv['limit']);
        $this->resp['list'] = $l;
        $this->resp['total'] = $c;

        return $this->ret_resp();
    }

    /*
        function user_membership_order_csvAction()
        {
            $this->paramlist = [
                'city_id' => 'string',
                'start_time' => 'datetime',
                'end_time' => 'datetime'
            ];
            $this->check_params();
            $this->check_token();

            if ($this->argv['end_time'] < $this->argv['start_time']) {
                throw_myexception(X_ERROR);
            }

            if (strtotime($this->argv['end_time']) - strtotime($this->argv['start_time']) >= 31 * 24 * 3600) {
                throw_myexception(X_ERROR, "查询时间跨度过大！");
            }

            (new FinReportModel())->user_membership_order_list_export($this->city_id_name_map()[$this->city_id],
                $this->city_id,
                $this->argv['start_time'],
                $this->argv['end_time']);
        }
    */
    function user_charge_order_listAction()
    {
        $this->paramlist = [
            'city_id' => 'optstring',
            'pno' => 'optint',
            'psize' => 'optint',
            'start_time' => 'datetime',
            'end_time' => 'datetime'
        ];
        $this->check_params();
        $this->check_token();

        list($l, $c) = (new FinReportModel())->user_charge_order_list($this->city_id_name_map(), $this->city_id, $this->argv['start_time'], $this->argv['end_time'], $this->argv['pos'], $this->argv['limit']);
        $this->resp['list'] = $l;
        $this->resp['total'] = $c;

        return $this->ret_resp();
    }

    /*
        function user_charge_order_csvAction()
        {
            $this->paramlist = [
                'city_id' => 'optstring',
                'start_time' => 'datetime',
                'end_time' => 'datetime'
            ];
            $this->check_params();
            $this->check_token();

            if ($this->argv['end_time'] < $this->argv['start_time']) {
                throw_myexception(X_ERROR);
            }

            if (strtotime($this->argv['end_time']) - strtotime($this->argv['start_time']) >= 31 * 24 * 3600) {
                throw_myexception(X_ERROR, "查询时间跨度过大！");
            }

            (new FinReportModel())->user_charge_order_list_export($this->city_id_name_map()[$this->city_id],
                $this->city_id,
                $this->argv['start_time'],
                $this->argv['end_time']);
        }
    */
}
